const Koa = require('koa');
const app = new Koa()

// ctx = context  全局公用上下文对象
// app.use(中间件)
app.use(async (ctx, next) => {
    const startTime = Date.now();
    console.log(1111, ctx.name)
    await next()
    const endTime = Date.now()
    console.log(1111, ctx.name, endTime - startTime, 'ms')
})
app.use(async (ctx, next) => {
    console.log(222, ctx.name)
    await next()
    console.log(222, ctx.name)
})
app.use(async (ctx, next) => {
    console.log(33, ctx.name)
    ctx.name = '王大海'
})

app.listen(8888, () => {
    console.log('服务已经启动 localhost:8888')
})